//
//  ShowBigImgUtil.swift
//  maopu
//
//  Created by 黄海波 on 2017/4/27.
//  Copyright © 2017年 maopu. All rights reserved.
//

import UIKit

class ShowBigImgUtil: NSObject {
    
    
    static func showBigImage(photoItems:[KSPhotoItem] , selectedIndex:Int , view:UIView){
        
        let browser:KSPhotoBrowser = KSPhotoBrowser.init(photoItems: photoItems, selectedIndex: UInt(selectedIndex))
        let vc = view.findController()
        browser.show(from: vc!)
    }
    
    static func showBigImage(imageViews:[UIImageView] , urls:[String] , selectedIndex:Int , view:UIView){
//        var photoItemList:[KSPhotoItem] = []
//        for i in 0..<urls.count{
//            let url:String = StringEngine.operateImageUrl(urls[i], imageSizeType: QiniuUrl_Style.ORIGINAL)
//            let item = KSPhotoItem.init(sourceView: imageViews[i], imageUrl: URL.init(string: url)!)
//            photoItemList.append(item)
//        }
//        let browser:KSPhotoBrowser = KSPhotoBrowser.init(photoItems: photoItemList, selectedIndex: UInt(selectedIndex))
//        let vc = view.findController()
//        browser.show(from: vc!)
        
        
    }
    
    static func showBigImage(imageViews:[UIImageView] , selectedGroupId:String? , selectedIndex:Int , view:UIViewController){
        var photoItemList:[KSPhotoItem] = []
        if selectedGroupId != nil{
            let group = getImageManager().groupDataManager.fetchGroupWithGroupId(selectedGroupId!)
            
            for i in 0..<group.totalCount{
                let asset = getImageManager().groupDataManager.fetchAsset(group, index: i)
//
//                asset.fetchFullScreenImageWithCompleteBlock({ (image, info) in
//                    var imageView:UIImageView?
//                    
//                    if i < imageViews.count{
//                        imageView = imageViews[i]
//                    }
//                    
//                    if imageView == nil{
//                        imageView = UIImageView()
//                    }
//                    if image != nil{
//                        let item = KSPhotoItem.init(sourceView: imageView!, image: image!)
//                        photoItemList.append(item)
//                    }
//                    
//                    if photoItemList.count >= group.totalCount{
//                        let browser:KSPhotoBrowser = KSPhotoBrowser.init(photoItems: photoItemList, selectedIndex: UInt(selectedIndex))
//                        browser.pageindicatorStyle = .text
//                        browser.backgroundStyle = .black
//                        browser.show(from: view)
//                    }
//                })
                
                asset.fetchOriginalImage(true, completeBlock: { (image, info) in
                    var imageView:UIImageView?
                    
                    if i < imageViews.count{
                        imageView = imageViews[i]
                    }
                    
                    if imageView == nil{
                        imageView = UIImageView()
                    }
                    if image != nil{
                        let item = KSPhotoItem.init(sourceView: imageView!, image: image!)
                        photoItemList.append(item)
                    }
                    
                    if photoItemList.count >= group.totalCount{
                        let browser:KSPhotoBrowser = KSPhotoBrowser.init(photoItems: photoItemList, selectedIndex: UInt(selectedIndex))
                        browser.pageindicatorStyle = .text
                        browser.backgroundStyle = .black
                        browser.show(from: view)
                    }
                })
                
//                asset.fetchOriginalImageWithCompleteBlock({ (image, info) in
//                    
//                    var imageView:UIImageView?
//                    
//                    if i < imageViews.count{
//                        imageView = imageViews[i]
//                    }
//                    
//                    if imageView == nil{
//                        imageView = UIImageView()
//                    }
//                    if image != nil{
//                        let item = KSPhotoItem.init(sourceView: imageView!, image: image!)
//                        photoItemList.append(item)
//                    }
//                    
//                    if photoItemList.count >= group.totalCount{
//                        let browser:KSPhotoBrowser = KSPhotoBrowser.init(photoItems: photoItemList, selectedIndex: UInt(selectedIndex))
//                        browser.pageindicatorStyle = .text
//                        browser.backgroundStyle = .black
//                        browser.show(from: view)
//                    }
//                })
            }
        }
    }
    
}
